package com.yuelao.util;

import lombok.extern.slf4j.Slf4j;
import sun.misc.BASE64Encoder;

import java.security.MessageDigest;

/**
 * Description
 *
 * @author fengliye
 * @version v1.0
 * @date 2020/02/11 14:47
 * @modify detail
 * 版本       修改人        修改时间      修改内容描述
 * ---------------------------------------------
 * <p>
 * ---------------------------------------------
 */
@Slf4j
public class MD5Util {
    private final static String MD5 = "MD5";

    public static String encode(String str) {
        try {
            MessageDigest md5 = MessageDigest.getInstance(MD5);
            //实现Base64的编码
            BASE64Encoder base64 = new BASE64Encoder();
            //进行加密
            String newStr = base64.encode(md5.digest(str.getBytes("utf-8")));
            log.info(newStr);
            return newStr;
        } catch (Exception e) {
            log.error("MD5 encode error !", e);
        }
        return "";
    }

    public static void main(String[] args) {
        encode("fengliye");
    }
}
